package test;

import org.hibernate.test.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.security.authentication.encoding.MessageDigestPasswordEncoder;

public class Main {

	/**
	 * @param args
	 */

	private MessageDigestPasswordEncoder pwdEncoder;

	public Main(MessageDigestPasswordEncoder pwdEncoder) {
		this.pwdEncoder = pwdEncoder;
	}

	public static void main(String[] args) {

		ApplicationContext ctx = new ClassPathXmlApplicationContext("SpringContextTest.xml");
		UserService userService = (UserService) ctx.getBean("userService");
		System.out.println("Test Services ");
		System.out.println("Total de usuarios: " + userService.findUserByNickName("admin").getLastName());
		Main m = (Main) ctx.getBean("mainTest");
		m.passwordDecoder("12345");
	}

	public void passwordDecoder(String password) {

		System.err.println(getPwdEncoder().encodePassword(password, ""));
	}

	public void setPwdEncoder(MessageDigestPasswordEncoder pwdEncoder) {
		this.pwdEncoder = pwdEncoder;
	}

	public MessageDigestPasswordEncoder getPwdEncoder() {
		return pwdEncoder;
	}

}
